#include "head.h"

void mkdirs(MYSQL* mysql,char* args,char* path ,int net_fd ,int user_id){
	//printf("mkdir:args=%s,path=%s,user_id=%d\n",args,path,user_id);
	int i = 0;
	char* parents_path;// = (char*)calloc(1024,sizeof(char));
	parents_path = path;
	int parents_id = isfile(mysql,path);
	/*printf("parents_id = %d\n",parents_id);
	printf("strlen(args)=%d\n",(int)strlen(args));
	printf("=======================================\n");*/
	while(i < (int)strlen(args)){

		int j = i;

		while(args[j] != '/' && j < (int)strlen(args)){
			j++;
		}
		char son_path[1024] = {0};
		for(int k = 0;k<j-i;k++){
			son_path[k] = args[k+i];
		}
		//printf("i=%d,j=%d,son_path=%s\n",i,j,son_path);
		//	parents_id = isfile(mysql,parents_path);
		//	printf("parents_id = %d\n",parents_id);
		parents_path = strcat(parents_path,"/");
		//printf("parents_path = %s\n",parents_path);
		parents_path = strcat(parents_path,son_path);
		//printf("parents_path = %s\n",parents_path);
		int son_id = isfile(mysql,parents_path);
		if(son_id == -1){//不存在则创建目录
			insert_file(mysql,parents_path,user_id,parents_id,0,son_path,NULL,NULL,0,0);
		}//这个目录存在跳过
		i = j+1;
		/*printf("i=%d\n",i);
		printf("|||||||||||||||||||||||||||\n");*/
		parents_id = isfile(mysql,parents_path);
		/*printf("parents_id = %d\n",parents_id);
		printf("&&&&&&&&&&&&&&&&&&&&&&&&&&\n");*/
	}
}
